﻿<UserControl x:Class="Chapters.Chapter16.RelSourceExample"
			 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
			 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
			 xmlns:Chapter16="clr-namespace:FSharp.Chapter16;assembly=FSharpLibrary">
	<UserControl.Resources>
		<Chapter16:LineChartModel x:Key="LineGraph" />
		<Chapter16:LineSegmentConverter x:Key="LineSegmentConverter" />

		<DataTemplate x:Key="LineSegmentTemplate">
			<Path Stroke="Black"
				  StrokeThickness="3"
				  StrokeEndLineCap="Round"
				  Stretch="None">
				<Path.Data>
					<MultiBinding Converter="{StaticResource LineSegmentConverter}">
						<Binding Path="."
								 RelativeSource="{RelativeSource PreviousData}" />
						<Binding Path="." />
						<Binding Path="ActualWidth"
								 RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Canvas}}" />
						<Binding Path="ActualHeight"
								 RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Canvas}}" />
					</MultiBinding>
				</Path.Data>
			</Path>
		</DataTemplate>

		<ControlTemplate x:Key="GraphTemplate">
			<Canvas IsItemsHost="True">
				<Canvas.Background>
					<ImageBrush ImageSource="/Resources;component/Chapter16/graph_background.png"
								TileMode="Tile"
								Viewport="0,0,50,50"
								ViewportUnits="Absolute" />


				</Canvas.Background>
			</Canvas>
		</ControlTemplate>
	</UserControl.Resources>
	<Grid>
		<ItemsControl ItemsSource="{Binding Path=DataPoints, Source={StaticResource LineGraph}}"
					  ItemTemplate="{StaticResource LineSegmentTemplate}"
					  Template="{StaticResource GraphTemplate}" />
	</Grid>
</UserControl>
